/*
 * BibliothequeGui.java
 *
 * Created on 30 mai 2007, 10:50
 */

package bibliotheque.client.gui;

import bibliotheque.client.Client;
import bibliotheque.document.DocumentId;
import bibliotheque.document.DocumentSummary;
import bibliotheque.events.BibliothequeQuitListener;
import bibliotheque.events.BibliothequeQuitOccuredEvent;
import bibliotheque.events.ErrorOccuredEvent;
import bibliotheque.events.ErrorOccuredListener;
import bibliotheque.events.StateChangedEvent;
import bibliotheque.events.StateChangedListener;
import bibliotheque.events.TransactionResultAddOccuredEvent;
import bibliotheque.events.TransactionResultConsultOccuredEvent;
import bibliotheque.events.TransactionResultFreeOccuredEvent;
import bibliotheque.events.TransactionResultInvalidateOccuredEvent;
import bibliotheque.events.TransactionResultOccuredListener;
import bibliotheque.events.TransactionResultReadOccuredEvent;
import bibliotheque.events.TransactionResultTakeOccuredEvent;
import bibliotheque.events.TransactionResultValidateOccuredEvent;
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.rmi.registry.Registry;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Iterator;
import javax.swing.GroupLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author  guillaume
 */
public class BibliothequeGui extends javax.swing.JPanel implements  TransactionResultOccuredListener, StateChangedListener, ErrorOccuredListener {
    
    public class MessageBox extends javax.swing.JFrame {
        
        private String message;
        
        public MessageBox(String message) {
            this.message = message;
            initComponents();
            this.setVisible(true);
        }
        
        // <editor-fold defaultstate="collapsed" desc=" Generated Code ">
        private void initComponents() {
            jLabel1 = new javax.swing.JLabel();
            jButton1 = new javax.swing.JButton();
            
            this.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
            jLabel1.setText(this.message);
            
            jButton1.setText("OK");
            jButton1.addMouseListener(new MouseAdapter() {
                public void mouseClicked(MouseEvent e) {
                    MessageBox.this.dispose();
                }
            });
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                    layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                    .addGap(154, 154, 154)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jButton1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.LEADING))
                    .addContainerGap(161, Short.MAX_VALUE))
                    );
            layout.setVerticalGroup(
                    layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                    .addContainerGap(33, Short.MAX_VALUE)
                    .addComponent(jLabel1)
                    .addGap(42, 42, 42)
                    .addComponent(jButton1)
                    .addGap(29, 29, 29))
                    );
            pack();
        }// </editor-fold>
        
        // Variables declaration - do not modify
        private javax.swing.JButton jButton1;
        private javax.swing.JLabel jLabel1;
        // End of variables declaration
        
    }
    
    private class JPanelConsultLayout extends GroupLayout{
        
        private DocumentId docId;
        
        public JPanelConsultLayout(Container host, final String summary, final String content, final DocumentId docId) {
            super(host);
            this.docId = docId;
            this.SetJpanelLayout(summary,content);
        }
        
        public void SetJpanelLayout(final String summary, final String content) {
            JScrollPane JScrollPaneSummary = new JScrollPane();
            JScrollPane JScrollPaneContent = new JScrollPane();
            
            JTextArea jTextAreaConsultSummary = new JTextArea();
            JTextArea jTextAreaConsultContent = new JTextArea();
            
            final JButton jButtonClose = new JButton();
            
            //this.jPanelConsultLayout = new GroupLayout(jPaneRead);
            
            jTextAreaConsultSummary.setLineWrap(true);
            jTextAreaConsultSummary.setText(summary);
            jTextAreaConsultSummary.setColumns(20);
            jTextAreaConsultSummary.setRows(5);
            jTextAreaConsultSummary.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Summary", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Dialog", 1, 14)));
            JScrollPaneSummary.setViewportView(jTextAreaConsultSummary);
            
            jTextAreaConsultContent.setLineWrap(true);
            jTextAreaConsultContent.setText(content);
            jTextAreaConsultContent.setColumns(20);
            jTextAreaConsultContent.setRows(5);
            jTextAreaConsultContent.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Content", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Dialog", 1, 14)));
            JScrollPaneContent.setViewportView(jTextAreaConsultContent);
            
            jButtonClose.setText("Close");
            
            jButtonClose.addMouseListener(new MouseAdapter() {
                public void mouseClicked(MouseEvent e) {
                    BibliothequeGui.this.MouseReleasedOnCloseButtonOccured(BibliothequeGui.JPanelConsultLayout.this);
                }
            });
            
            this.setHorizontalGroup(
                    this.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, this.createSequentialGroup()
                    .addContainerGap()
                    .addGroup(this.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(JScrollPaneSummary, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 540, Short.MAX_VALUE)
                    .addComponent(JScrollPaneContent, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 540, Short.MAX_VALUE)
                    .addComponent(jButtonClose))
                    .addContainerGap())
                    );
            this.setVerticalGroup(
                    this.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(this.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(JScrollPaneSummary, javax.swing.GroupLayout.PREFERRED_SIZE, 147, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(JScrollPaneContent, javax.swing.GroupLayout.DEFAULT_SIZE, 294, Short.MAX_VALUE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(jButtonClose)
                    .addContainerGap())
                    );
        }
        
        public DocumentId GetDocId(){
            return this.docId;
        }
    }
    
    private Client client;
    private Registry rmi_registry;
    private int current_state;
    
    private Object[][] object;
    private Hashtable<DocumentId, DocumentSummary> list_DocumentSummary ;
    private ArrayList<DocumentId> list_free;
    //private ArrayList<DocumentId> list_read;
    private Hashtable<DocumentId,JPanel> ListJPanelRead;
    
    private ArrayList<DocumentSummary> list_test;
    
    protected ArrayList<BibliothequeQuitListener> bibliothequeQuitListener;
    
    private ArrayList<DocumentId> GetTableTotalState() {
        ArrayList<DocumentId> idlist = new ArrayList<DocumentId>();
        
        for(int i = 0 ; i<this.jTableResult.getRowCount() ; i++) {
            idlist.add( (DocumentId) this.object[i][3]);
        }
        
        return idlist;
    }
    
    private ArrayList<DocumentId> GetTableTrueState() {
        ArrayList<DocumentId> idlist = new ArrayList<DocumentId>();
        
        for(int i = 0 ; i<this.jTableResult.getRowCount() ; i++) {
            if((Boolean)this.jTableResult.getModel().getValueAt(i,0) == true) {
                idlist.add((DocumentId)this.object[i][3]);
            }
        }
        
        System.out.println(idlist.size());
        
        return idlist;
    }
    
    private ArrayList<DocumentId> GetTableFalseState() {
        ArrayList<DocumentId> idlist = new ArrayList<DocumentId>();
        
        for(int i = 0 ; i<this.jTableResult.getRowCount() ; i++) {
            if((Boolean)this.jTableResult.getModel().getValueAt(i,0) == false) {
                idlist.add((DocumentId)this.object[i][3]);
            }
        }
        
        return idlist;
    }
    
    private void SetTable(/*ArrayList<DocumentSummary> result*/) {
        try {
// TODO add your handling code here:
            
            
            
            //  this.client.Search(this.jTextFieldSearch.getText(),this.client.GetServiceName());
            
            //this.client.InitiateSearch(this.jTextFieldSearch.getText(),this.client.GetServiceName());
            
            /* Test */
/*
            DocumentId docId1 = new DocumentId("192.168.0.1",1);
            DocumentId docId2 = new DocumentId("192.168.0.2",2);
            DocumentId docId3 = new DocumentId("192.168.0.3",3);
            DocumentId docId4 = new DocumentId("192.168.0.4",4);
 
 
            this.list_DocumentSummary = new Hashtable<DocumentId, DocumentSummary>();
            DocumentSummary doc1 = new DocumentSummary(docId1,"toto1", "toto a la plage");
            DocumentSummary doc2 = new DocumentSummary(docId2,"toto2", "toto a la mer");
            DocumentSummary doc3 = new DocumentSummary(docId3, "toto3", "toto a la piscine");
            DocumentSummary doc4 = new DocumentSummary(docId4, "toto4", "toto a la campagne");
 
 
            this.list_test = new ArrayList<DocumentSummary>();
            this.list_test.add(doc1);
            this.list_test.add(doc2);
            this.list_test.add(doc3);
            this.list_test.add(doc4);
 
            this.list_DocumentSummary.put(docId1,doc1);
            this.list_DocumentSummary.put(docId2,doc2);
            this.list_DocumentSummary.put(docId3,doc3);
            this.list_DocumentSummary.put(docId4,doc4);
 */
            /* END Test */
            this.object = null;
            Enumeration<DocumentSummary> enu ;
            DocumentSummary doc ;
            int row ;
            if (!this.list_DocumentSummary.isEmpty()){
                
                this.object = new Object[/*result*/list_DocumentSummary.size()][4];
                
                enu = /*result*/list_DocumentSummary.elements();
                row = 0;
                while (enu.hasMoreElements()) {
                    doc = enu.nextElement();
                    this.object[row][0]=new Boolean(false);
                    this.object[row][1]=doc.GetTitle();
                    this.object[row][2]=doc.GetSummary();
                    row++;
                }
            }
            
            this.jTableResult.setModel(new DefaultTableModel(object,new String [] {"Select", "Title", "Summary" }) {
                /*
                 * JTable uses this method to determine the default renderer/
                 * editor for each cell.  If we didn't implement this method,
                 * then the last column would contain text ("true"/"false"),
                 * rather than a check box.
                 */
                public Class getColumnClass(int c) {
                    return getValueAt(0, c).getClass();
                }
                
                public boolean isCellEditable(int row, int col) {
                    //Note that the data/cell address is constant,
                    //no matter where the cell appears onscreen.
                    if (col > 0) {
                        return false;
                    } else {
                        return true;
                    }
                }
            });
            //this.jTableResult.s
            
            if (!this.list_DocumentSummary.isEmpty()){
                enu = /*result*/list_DocumentSummary.elements();
                row = 0;
                while (enu.hasMoreElements()) {
                    doc = enu.nextElement();
                    this.object[row][3]=doc.GetId();
                    row++;
                }
            }
            
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        
    }
    
    private void FreeTable(){
        this.list_DocumentSummary.clear();
        this.object = null;
        this.jTableResult.setModel(new DefaultTableModel(object,new String [] {"Select", "Title", "Summary" }) {
                /*
                 * JTable uses this method to determine the default renderer/
                 * editor for each cell.  If we didn't implement this method,
                 * then the last column would contain text ("true"/"false"),
                 * rather than a check box.
                 */
            public Class getColumnClass(int c) {
                return getValueAt(0, c).getClass();
            }
            
            public boolean isCellEditable(int row, int col) {
                //Note that the data/cell address is constant,
                //no matter where the cell appears onscreen.
                if (col > 0) {
                    return false;
                } else {
                    return true;
                }
            }
        });
        //this.SetTable();
    }
    
    
    /**************************************************************************/
    /*                                                                        */
    /*                      Gestion des evenements                            */
    /*                                                                        */
    /**************************************************************************/
    
    public void MouseReleasedOnCloseButtonOccured(JPanelConsultLayout jpcl){
        //On enleve le document fermé de la liste des documents en lecture
        this.ListJPanelRead.remove(jpcl.GetDocId());
        
        this.jTabbedPane1.remove(this.jTabbedPane1.getSelectedIndex());
    }
    
    public void AddBibliothequeQuitListener(BibliothequeQuitListener listener) {
        this.bibliothequeQuitListener.add(listener);
    }
    
    public void RemoveBibliothequeQuitListener(BibliothequeQuitListener listener) {
        this.bibliothequeQuitListener.remove(listener);
    }
    
    protected void BibliothequeQuitOccured(){
        BibliothequeQuitOccuredEvent event = new BibliothequeQuitOccuredEvent(this);
        for(int i=0;i<this.bibliothequeQuitListener.size();i++) {
            this.bibliothequeQuitListener.get(i).BibliothequeQuitOccured(event);
        }
    }
    
    public void StateChanged(StateChangedEvent event){
        this.jLabelState.setText(event.GetState());
    }
    
    public void ErrorOccured(ErrorOccuredEvent event) {
        this.jTextLogArea.append("ERROR : \n");
        this.jTextLogArea.append("        " + event.GetError());
    }
    
    
    public void TransactionResultAddOccured(TransactionResultAddOccuredEvent event) {
        this.jTextLogArea.append("\n");
        this.jTextLogArea.append("ADD operation : \n");
        if(event.GetAddResult()) {
            this.jTextLogArea.append("                ADD successed \n");
            this.jTextFieldAddTitle.setText("");
            this.jTextAreaAddSummary.setText("");
            this.jTextAreaAddContent.setText("");
            this.UpdateAddButton();
        } else {
            this.jTextLogArea.append("                ADD failed \n");
        }
        
        this.SetAllEnable(true);
        
    }
    
    public void TransactionResultTakeOccured(TransactionResultTakeOccuredEvent event) {
        this.jTextLogArea.append("\n");
        this.jTextLogArea.append("TAKE operation : \n");
        if(event.GetTakeResult().isEmpty())
            this.jTextLogArea.append("                 No Document found\n");
        else this.jTextLogArea.append("                 "+event.GetTakeResult().size()+" Documents found");
        
        Iterator<DocumentSummary> iter = event.GetTakeResult().iterator();
        DocumentSummary doc;
        while(iter.hasNext()){
            doc = iter.next();
            this.list_DocumentSummary.put(doc.GetId(),doc);
        }
        
        this.SetTable();
        this.SetAllEnable(true);
    }
    
    public void TransactionResultConsultOccured(TransactionResultConsultOccuredEvent event) {
        this.jTextLogArea.append("\n");
        this.jTextLogArea.append("CONSULT operation : \n");
        if(event.GetConsultResult().isEmpty())
            this.jTextLogArea.append("                 No Document found\n");
        else this.jTextLogArea.append("                 "+event.GetConsultResult().size()+" Documents found");
        
        this.FreeTable();
        
        Iterator<DocumentSummary> iter = event.GetConsultResult().iterator();
        DocumentSummary doc;
        while(iter.hasNext()){
            doc = iter.next();
            this.list_DocumentSummary.put(doc.GetId(),doc);
        }
        
        this.SetTable();
        this.SetAllEnable(true);
    }
    
    public void TransactionResultFreeOccured(TransactionResultFreeOccuredEvent event) {
        this.jTextLogArea.append("\n");
        this.jTextLogArea.append("FREE operation : \n");
        if(event.GetFreeResult()) {
            //System.out.println("FREE RESULT : \n ID : "+event.GetDocId().GetId()+"\nIP : "+event.GetDocId().GetIp());
            System.out.println("presence du docId dans la liste des docs : "+this.list_DocumentSummary.containsKey(event.GetDocId()));
            System.out.println("nombre de docs before: " + this.list_DocumentSummary.size());
            System.out.println("liste des list_free : \n" + this.list_free.toString());
            System.out.println("presence du docId dans la liste des free : " + this.list_free.contains(event.GetDocId()));
            this.list_free.remove(event.GetDocId());
            this.list_DocumentSummary.remove(event.GetDocId());
            System.out.println("nombre de docs after: " + this.list_DocumentSummary.size());
            this.jTextLogArea.append("                 Document removed\n");
        } else {
            this.jTextLogArea.append("                 FREE failed\n");
        }
        
        this.SetTable();
        this.SetAllEnable(true);
    }
    
    public void TransactionResultReadOccured(TransactionResultReadOccuredEvent event) {
        
        this.jTextLogArea.append("\n");
        this.jTextLogArea.append("READ operation : \n");
        JPanel jPanelRead = new JPanel();
        JPanelConsultLayout jpcl = new JPanelConsultLayout(jPanelRead,this.list_DocumentSummary.get(event.GetReadDocIdResult()).GetSummary(),event.GetReadContentResult(),event.GetReadDocIdResult());
        jPanelRead.setLayout(jpcl);
        this.ListJPanelRead.put(event.GetReadDocIdResult(),jPanelRead);
        this.jTabbedPane1.addTab(this.list_DocumentSummary.get(event.GetReadDocIdResult()).GetTitle(),jPanelRead);
        this.jTextLogArea.append("                 Panel created \n");
        
        this.SetAllEnable(true);
    }
    
    public void TransactionResultValidateOccured(TransactionResultValidateOccuredEvent event) {
        this.jTextLogArea.append("\n");
        this.jTextLogArea.append("VALIDATE operation : \n");
        if(event.GetValidateResult()){
            this.jTextLogArea.append("                 VALIDATE successed \n");
            this.FreeTable();
        } else this.jTextLogArea.append("                 VALIDATE failed \n");
        
        new MessageBox("Validate Occured").setLocationRelativeTo(this);
        
        this.SetAllEnable(true);
    }
    
    public void TransactionResultInvalidateOccured(TransactionResultInvalidateOccuredEvent event) {
        this.jTextLogArea.append("\n");
        this.jTextLogArea.append("INVALIDATE operation : \n");
        if(event.GetInvalidateResult()){
            this.jTextLogArea.append("                   INVALIDATE successed \n");
            this.FreeTable();
        }
        
        else this.jTextLogArea.append("                   INVALIDATE failed \n");
        
        new MessageBox("Invalidate Occured").setLocationRelativeTo(this);
        
        this.SetAllEnable(true);
    }
    
    
    private boolean buttonAdd;
    private boolean buttonSearch;
    private boolean buttonFree;
    private boolean buttonRead;
    private boolean buttonValidate;
    private boolean buttonInvalidate;
    
    private void SetAllEnable(boolean set) {
        if (!set){
            System.out.println("mise à "+set+" de tous les boutons");
            this.jButtonAdd.setEnabled(set);
            this.jButtonFree.setEnabled(set);
            this.jButtonInvalidate.setEnabled(set);
            this.jButtonRead.setEnabled(set);
            this.jButtonSearch.setEnabled(set);
            this.jButtonValidate.setEnabled(set);
        } else {
            this.jButtonAdd.setEnabled(this.buttonAdd);
            this.jButtonFree.setEnabled(this.buttonFree);
            this.jButtonInvalidate.setEnabled(this.buttonInvalidate);
            this.jButtonRead.setEnabled(this.buttonRead);
            this.jButtonSearch.setEnabled(this.buttonSearch);
            this.jButtonValidate.setEnabled(this.buttonValidate);
        }
    }
    
    private void UpdateAddButton() {
        if( !this.jTextFieldAddTitle.getText().isEmpty() && !this.jTextAreaAddSummary.getText().isEmpty() && !this.jTextAreaAddContent.getText().isEmpty()){
            this.buttonAdd = true;
            this.jButtonAdd.setEnabled(this.buttonAdd);
        } else {
            this.buttonAdd = false;
            this.jButtonAdd.setEnabled(this.buttonAdd);
        }
        
    }
    
    
    public BibliothequeGui(Client client) {
        /* Initialisation de l'interface */
        
        initComponents();
        
        /* Initialisation des variables de classe */
        this.bibliothequeQuitListener = new ArrayList<BibliothequeQuitListener>();
        this.client = client;
        this.list_DocumentSummary = new Hashtable<DocumentId, DocumentSummary>();
        this.list_free = new ArrayList<DocumentId>();
        this.ListJPanelRead = new Hashtable<DocumentId,JPanel>();
        
        /* Inscription des listener */
        this.client.AddErrorOccuredListener(this);
        this.client.AddTransactionResultOccuredListener(this);
        this.client.AddStateChangedListener(this);
        
        /* Vidage du tableau resultat */
        this.FreeTable();
        
        this.jTextLogArea.setAutoscrolls(true);
        this.jScrollPane1.setAutoscrolls(true);
        this.jScrollPane2.setAutoscrolls(true);
        this.jScrollPane3.setAutoscrolls(true);
        this.jScrollPane4.setAutoscrolls(true);
        
        this.jRadioButtonConsult.setSelected(true);
        this.jRadioButtonRetrait.setSelected(false);
        
        this.jTextLogArea.setText(this.client.GetServiceName().toUpperCase() + " SERVICE STARTED \n\n");
        if(this.client.GetRegistryState()) {
            this.jTextLogArea.append("RmiRegistry : OK \n");
        }
        if(this.client.GetRegistryState()==false){
            this.jTextLogArea.append("RmiRegistry : FAILED \n");
        }
        if (this.client.GetIp().isEmpty()) {
            this.jTextLogArea.append("Client IP : FAILED \n\n");
        }
        if (!this.client.GetIp().isEmpty()) {
            this.jTextLogArea.append("Client IP : " + this.client.GetIp() + " \n\n");
        }
        
        
    }
    
    /** Creates new form BibliothequeGui */
    public BibliothequeGui() {
        initComponents();
        this.list_DocumentSummary = new Hashtable<DocumentId, DocumentSummary>();
        this.list_free = new ArrayList<DocumentId>();
        //this.list_read = new ArrayList<DocumentId>();
        this.ListJPanelRead = new Hashtable<DocumentId,JPanel>();
        this.jRadioButtonConsult.setSelected(true);
        this.jRadioButtonRetrait.setSelected(false);
        //this.jButtonSearch.addMouseListener(this);
        //this.client = client;
        //this.client.AddTransactionResultOccuredListener(this);
        //this.client.AddStateChangedListener(this);
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents() {
        jPanel5 = new javax.swing.JPanel();
        jButtonSearch = new javax.swing.JButton();
        jRadioButtonConsult = new javax.swing.JRadioButton();
        jRadioButtonRetrait = new javax.swing.JRadioButton();
        jTextFieldSearch = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jPanel4 = new javax.swing.JPanel();
        jButtonAdd = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTextAreaAddSummary = new javax.swing.JTextArea();
        jScrollPane3 = new javax.swing.JScrollPane();
        jTextAreaAddContent = new javax.swing.JTextArea();
        jTextFieldAddTitle = new javax.swing.JTextField();
        jPanel3 = new javax.swing.JPanel();
        jLabelState = new javax.swing.JLabel();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTableResult = new javax.swing.JTable();
        jPanel6 = new javax.swing.JPanel();
        jButtonValidate = new javax.swing.JButton();
        jButtonInvalidate = new javax.swing.JButton();
        jButtonQuit = new javax.swing.JButton();
        jButtonRead = new javax.swing.JButton();
        jButtonFree = new javax.swing.JButton();
        jScrollPane4 = new javax.swing.JScrollPane();
        jTextLogArea = new javax.swing.JTextArea();

        jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Search", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Dialog", 1, 14)));
        jButtonSearch.setText("Search");
        jButtonSearch.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonSearchActionPerformed(evt);
            }
        });

        jRadioButtonConsult.setText("Consult");
        jRadioButtonConsult.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        jRadioButtonConsult.setMargin(new java.awt.Insets(0, 0, 0, 0));
        jRadioButtonConsult.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButtonConsultActionPerformed(evt);
            }
        });

        jRadioButtonRetrait.setText("Retrait ");
        jRadioButtonRetrait.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        jRadioButtonRetrait.setMargin(new java.awt.Insets(0, 0, 0, 0));
        jRadioButtonRetrait.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButtonRetraitActionPerformed(evt);
            }
        });

        jTextFieldSearch.setText("Search ...");
        jTextFieldSearch.setEnabled(false);
        jTextFieldSearch.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTextFieldSearchMouseClicked(evt);
            }
        });

        jLabel1.setText(" Search :");

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel1))
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addGap(69, 69, 69)
                        .addComponent(jRadioButtonConsult)
                        .addGap(100, 100, 100)
                        .addComponent(jRadioButtonRetrait)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 137, Short.MAX_VALUE)
                        .addComponent(jButtonSearch))
                    .addComponent(jTextFieldSearch, javax.swing.GroupLayout.DEFAULT_SIZE, 508, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTextFieldSearch, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(10, 10, 10)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jRadioButtonRetrait)
                    .addComponent(jRadioButtonConsult)
                    .addComponent(jButtonSearch))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Deposite", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Dialog", 1, 14)));
        jButtonAdd.setText("Add");
        jButtonAdd.setEnabled(false);
        jButtonAdd.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButtonAddMouseClicked(evt);
            }
        });

        jTextAreaAddSummary.setColumns(20);
        jTextAreaAddSummary.setRows(5);
        jTextAreaAddSummary.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Summary", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Dialog", 1, 14)));
        jTextAreaAddSummary.addCaretListener(new javax.swing.event.CaretListener() {
            public void caretUpdate(javax.swing.event.CaretEvent evt) {
                jTextAreaAddSummaryCaretUpdate(evt);
            }
        });

        jScrollPane2.setViewportView(jTextAreaAddSummary);

        jTextAreaAddContent.setColumns(20);
        jTextAreaAddContent.setRows(5);
        jTextAreaAddContent.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Content", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Dialog", 1, 14)));
        jTextAreaAddContent.addCaretListener(new javax.swing.event.CaretListener() {
            public void caretUpdate(javax.swing.event.CaretEvent evt) {
                jTextAreaAddContentCaretUpdate(evt);
            }
        });

        jScrollPane3.setViewportView(jTextAreaAddContent);

        jTextFieldAddTitle.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Title", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Dialog", 1, 14)));
        jTextFieldAddTitle.addCaretListener(new javax.swing.event.CaretListener() {
            public void caretUpdate(javax.swing.event.CaretEvent evt) {
                jTextFieldAddTitleCaretUpdate(evt);
            }
        });

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 496, Short.MAX_VALUE)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 496, Short.MAX_VALUE)
                    .addComponent(jTextFieldAddTitle, javax.swing.GroupLayout.DEFAULT_SIZE, 496, Short.MAX_VALUE)
                    .addComponent(jButtonAdd, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addComponent(jTextFieldAddTitle, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonAdd, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Current State", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Dialog", 1, 14)));
        jLabelState.setText("Waiting for action");

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGap(195, 195, 195)
                .addComponent(jLabelState)
                .addContainerGap(214, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addComponent(jLabelState)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jTableResult.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null}
            },
            new String [] {
                "Select", "Title", "Summary"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, true
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jTableResult.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTableResultMouseClicked(evt);
            }
        });

        jScrollPane1.setViewportView(jTableResult);

        jTabbedPane1.addTab("Results", jScrollPane1);

        jPanel6.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "End of the Transaction", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Dialog", 1, 14)));
        jButtonValidate.setText("Validate");
        jButtonValidate.setEnabled(false);
        jButtonValidate.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButtonValidateMouseClicked(evt);
            }
        });

        jButtonInvalidate.setText("Invalidate");
        jButtonInvalidate.setEnabled(false);
        jButtonInvalidate.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButtonInvalidateMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel6Layout.createSequentialGroup()
                .addGap(111, 111, 111)
                .addComponent(jButtonValidate)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 172, Short.MAX_VALUE)
                .addComponent(jButtonInvalidate)
                .addGap(114, 114, 114))
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButtonInvalidate)
                    .addComponent(jButtonValidate))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jButtonQuit.setText("Quit");
        jButtonQuit.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButtonQuitMouseClicked(evt);
            }
        });

        jButtonRead.setText("Read");
        jButtonRead.setEnabled(false);
        jButtonRead.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButtonReadMouseClicked(evt);
            }
        });

        jButtonFree.setText("Free");
        jButtonFree.setEnabled(false);
        jButtonFree.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButtonFreeMouseClicked(evt);
            }
        });

        jScrollPane4.setAutoscrolls(true);
        jTextLogArea.setColumns(20);
        jTextLogArea.setEditable(false);
        jTextLogArea.setRows(5);
        jTextLogArea.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Log Area", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Dialog", 1, 14)));
        jTextLogArea.setDisabledTextColor(new java.awt.Color(51, 0, 51));
        jScrollPane4.setViewportView(jTextLogArea);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 530, Short.MAX_VALUE)
                    .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jTabbedPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 592, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                    .addComponent(jButtonFree, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jButtonRead, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addComponent(jButtonQuit, javax.swing.GroupLayout.PREFERRED_SIZE, 138, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(42, 42, 42)
                        .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 399, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jButtonRead)
                            .addComponent(jButtonFree))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButtonQuit))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane4, 0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents
    
    private void jTextAreaAddContentCaretUpdate(javax.swing.event.CaretEvent evt) {//GEN-FIRST:event_jTextAreaAddContentCaretUpdate
// TODO add your handling code here:
        this.UpdateAddButton();
    }//GEN-LAST:event_jTextAreaAddContentCaretUpdate
    
    private void jTextAreaAddSummaryCaretUpdate(javax.swing.event.CaretEvent evt) {//GEN-FIRST:event_jTextAreaAddSummaryCaretUpdate
// TODO add your handling code here:
        this.UpdateAddButton();
    }//GEN-LAST:event_jTextAreaAddSummaryCaretUpdate
    
    private void jTextFieldAddTitleCaretUpdate(javax.swing.event.CaretEvent evt) {//GEN-FIRST:event_jTextFieldAddTitleCaretUpdate
// TODO add your handling code here:
        this.UpdateAddButton();
    }//GEN-LAST:event_jTextFieldAddTitleCaretUpdate
    
    private void jButtonAddMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButtonAddMouseClicked
// TODO add your handling code here:
        
        this.SetAllEnable(false);
        
        this.client.Add(this.jTextFieldAddTitle.getText(), this.jTextAreaAddSummary.getText(), this.jTextAreaAddContent.getText());
        
        
        //this.SetAllEnable(true);
    }//GEN-LAST:event_jButtonAddMouseClicked
    
    private void jButtonQuitMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButtonQuitMouseClicked
// TODO add your handling code here:
        
        /* Invalidation de la transaction avant de quitter */
        
        this.client.Invalidate();
        
        if (this.client != null) {
            this.client.RemoveErrorOccuredListener(this);
            this.client.RemoveStateChangedListener(this);
            this.client.RemoveTransactionResultListener(this);
        }
        
        this.BibliothequeQuitOccured();
    }//GEN-LAST:event_jButtonQuitMouseClicked
    
    private void jTableResultMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTableResultMouseClicked
// TODO add your handling code here:
        
        if (this.GetTableTrueState().size() == 0) {
            this.buttonFree = false;
            this.buttonRead = false;
        }
        
        else {
            this.buttonFree = true;
            this.buttonRead = true;
        }
        
        this.jButtonFree.setEnabled(this.buttonFree);
        this.jButtonRead.setEnabled(this.buttonRead);
        
        System.out.println("valeur de l'objet : " + this.jTableResult.getModel().getValueAt(0,0));
    }//GEN-LAST:event_jTableResultMouseClicked
    
    private void jButtonInvalidateMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButtonInvalidateMouseClicked
// TODO add your handling code here:
        this.SetAllEnable(false);
        
        this.buttonInvalidate = false;
        this.buttonValidate = false;
        this.buttonSearch = true;
        
        Enumeration<JPanel> enu = this.ListJPanelRead.elements();
        while(enu.hasMoreElements()){
            this.jTabbedPane1.remove(enu.nextElement());
        }
        
        this.ListJPanelRead.clear();
        //this.jButtonInvalidate.setEnabled(this.buttonInvalidate);
        //this.jButtonSearch.setEnabled(this.buttonSearch);
        this.client.Invalidate();
        //this.TransactionResultInvalidateOccured(new TransactionResultInvalidateOccuredEvent(this,true));
    }//GEN-LAST:event_jButtonInvalidateMouseClicked
    
    private void jButtonValidateMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButtonValidateMouseClicked
// TODO add your handling code here:
        this.SetAllEnable(false);
        this.buttonValidate = false;
        this.buttonValidate = false;
        this.buttonSearch = true;
        //this.jButtonValidate.setEnabled(this.buttonValidate);
        //this.jButtonSearch.setEnabled(this.buttonSearch);
        this.client.Validate();
        
        //this.TransactionResultValidateOccured(new TransactionResultValidateOccuredEvent(this,true));
    }//GEN-LAST:event_jButtonValidateMouseClicked
    
    private void jButtonReadMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButtonReadMouseClicked
// TODO add your handling code here:
        this.SetAllEnable(false);
        
        ArrayList<DocumentId> localList = new ArrayList<DocumentId>();
        localList = this.GetTableTrueState();
        
        /* Demande de lecture pour les documents selectionnés*/
        Iterator<DocumentId> iter = localList.iterator();
        DocumentId docId;
        while(iter.hasNext()){
            docId = iter.next();
            if (!this.ListJPanelRead.containsKey(docId)){
                this.client.Read(docId) ;
                System.out.println("demande de read pour doc n° " + docId.GetId() + "sur le serveur : " + docId.GetIp());
            }
        }
        
        
        
    }//GEN-LAST:event_jButtonReadMouseClicked
    
    private void jButtonFreeMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButtonFreeMouseClicked
// TODO add your handling code here:
        this.SetAllEnable(false);
        
        
        ArrayList<DocumentId> localList = new ArrayList<DocumentId>();
        localList = this.GetTableTrueState();
        
        /* On recupere la liste des Doc selectionnés */
        this.list_free = localList;
        
        DocumentId docId;
        Iterator<DocumentId> iter = localList.iterator();
        
        /* On lance une vague de libration pour tous les docs selectionnés
         * Si un onglet de lecture est ouvert, il est automatiquement fermé
         */
        while(iter.hasNext()){
            docId = iter.next();
            //on ferme les onglets de lecture ouverts pour le document à libérer
            if(this.ListJPanelRead.containsKey(docId)){
                this.jTabbedPane1.remove(this.ListJPanelRead.get(docId));
            }
            this.client.Free(docId);
        }
        
    }//GEN-LAST:event_jButtonFreeMouseClicked
    
    private void jTextFieldSearchMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTextFieldSearchMouseClicked
// TODO add your handling code here:
        this.jTextFieldSearch.setEnabled(true);
        this.jTextFieldSearch.setText("");
        this.jTextFieldSearch.setEditable(true);
    }//GEN-LAST:event_jTextFieldSearchMouseClicked
    
    private void jRadioButtonRetraitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButtonRetraitActionPerformed
// TODO add your handling code here:
        this.jRadioButtonRetrait.setSelected(true);
        this.jRadioButtonConsult.setSelected(false);
    }//GEN-LAST:event_jRadioButtonRetraitActionPerformed
    
    private void jRadioButtonConsultActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButtonConsultActionPerformed
// TODO add your handling code here:
        this.jRadioButtonConsult.setSelected(true);
        this.jRadioButtonRetrait.setSelected(false);
    }//GEN-LAST:event_jRadioButtonConsultActionPerformed
    
    private void jButtonSearchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonSearchActionPerformed
        
        this.SetAllEnable(false);
        
        this.buttonInvalidate = true;
        this.buttonValidate = true;
        this.buttonSearch = false;
        
        /* Invalidation de la transaction précédente pour une nouvelle recherche */
        //this.client.Invalidate();
        
        /* Suivant le type de demande, la bonne fonction est lancée */
        if(this.jRadioButtonConsult.isSelected())
            this.client.Consult(this.jTextFieldSearch.getText());
        else
            this.client.WithDraw(this.jTextFieldSearch.getText());
        
        
        
    }//GEN-LAST:event_jButtonSearchActionPerformed
    
    
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonAdd;
    private javax.swing.JButton jButtonFree;
    private javax.swing.JButton jButtonInvalidate;
    private javax.swing.JButton jButtonQuit;
    private javax.swing.JButton jButtonRead;
    private javax.swing.JButton jButtonSearch;
    private javax.swing.JButton jButtonValidate;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabelState;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JRadioButton jRadioButtonConsult;
    private javax.swing.JRadioButton jRadioButtonRetrait;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTable jTableResult;
    private javax.swing.JTextArea jTextAreaAddContent;
    private javax.swing.JTextArea jTextAreaAddSummary;
    private javax.swing.JTextField jTextFieldAddTitle;
    private javax.swing.JTextField jTextFieldSearch;
    private javax.swing.JTextArea jTextLogArea;
    // End of variables declaration//GEN-END:variables
    
}
